package net.neiquan.neiquandemowithkf.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import net.neiquan.neiquandemowithkf.R;
import net.neiquan.neiquandemowithkf.entity.Good;
import net.neiquanlib.base.MyBaseAdapterRecycleView;
import net.neiquanlib.utils.ImageUtils;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 作者 ： hjb
 * 时间 ： 2016/7/26.
 */


public class GoodAdapter extends MyBaseAdapterRecycleView<Good, GoodAdapter.ViewHolder> {

    public GoodAdapter(Context context, List<Good> data) {
        super(context, data);
    }


    @Override
    protected ViewHolder getViewHolder() {
        return new ViewHolder(mInflater.inflate(R.layout.item_one, null));
    }

    @Override
    protected void onBindViewHolder_(ViewHolder holder, int position) {
        Good commodity = data.get(position);

        holder.mTvName.setText(commodity.getCommodityName() == null ? "" : commodity.getCommodityName());
        holder.mTvNum.setText(commodity.getSellByMonth() + "" == null ? "" : "月售:" + commodity.getSellByMonth() + "");
        holder.mTvPrice.setText(commodity.getPrice() + "" == null ? "" : "￥" + commodity.getPrice() + "");
        if (commodity.getUrl() != null) {
            ImageUtils.LoadPicture(commodity.getUrl(), holder.mImgOne);
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.img_one)
        ImageView mImgOne;
        @InjectView(R.id.tv_name)
        TextView mTvName;
        @InjectView(R.id.tv_num)
        TextView mTvNum;
        @InjectView(R.id.tv_price)
        TextView mTvPrice;
        @InjectView(R.id.tv_priceOriginal)
        TextView mTvPriceOriginal;

        ViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
}
